package com.service.scheduler.sched;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerKey;

import com.service.cache.CacheManager;
import com.service.other.Logger;
import com.service.scheduler.job.ChangePasswordJob;
import com.service.scheduler.server.SchedulerCreator;

public class PasswordSched {
	
	private Scheduler sched;
	
	public void init(){
		try {
			sched = SchedulerCreator.createScheduler(PasswordSched.class.getSimpleName(),1,5);
			JobKey jobKey = SchedulerCreator.createJobKey("changePwd", "com.service.other");
			TriggerKey triggerKey = SchedulerCreator.createTriggerKey("changePwd","com.service.other");
			String cronExpr = "0 0 1 * * ?";
			JobDetail job = SchedulerCreator.createJob(jobKey, ChangePasswordJob.class);
			CronTrigger cronTrigger = SchedulerCreator.createCronTrigger(triggerKey,cronExpr);
			sched.scheduleJob(job, cronTrigger);
			CacheManager.instance().schedMap.put(sched.getSchedulerName(),sched);
		} catch (SchedulerException e) {
			Logger.err(e);
		}
	}
}
